#!/bin/bash

_chk_err ()
{
	echo " ERROR "
}

set_slk_version ()
{
	if [ ! -x /sbin/installpkg -a ! -x /bin/tar-1.13 ]; then
		echo " Using slackware tools ..."
		tar xOfv ./src/slackware/a/tar-*tgz bin/tar-1.13 > ./bin/tar-1.13
		tar xOfv ./src/slackware/a/pkgtools-*tgz sbin/installpkg > ./bin/installpkg
		chmod 755 ./bin/installpkg ./bin/tar-1.13
	fi
}

set -eET
set -o pipefail
trap '_chk_err' ERR
export -f _chk_err

./bin/mk-dir-struct.sh

#./bin/fetch-src

set_slk_version

./bin/auxbuildroot/prepare.clean
./bin/auxbuildroot/prepare.main
./bin/auxbuildroot/prepare.cpfiles
./bin/auxbuildroot/prepare.slkinstall
./bin/auxbuildroot/prepare.slkinstall.post

#./bin/nemo_pkg/BUILD-ALL 2>&1 | tee ./tmp/build_nemo_pkg.log
./bin/installcd/BUILD-ALL 
#./bin/initram/BUILD-ALL 

#./bin/kernel/BUILD-ALL

./bin/auxbuildroot/cp-pkgs-to-cdtree

./bin/cp-cdtree-files

./bin/make-iso

echo -e "\n MAKE-CD.sh: DONE\n "

set +eET
